<template>
    <cover-view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
        <cover-view class="tabbar-item"
            v-for="(item, index1) in list" 
            :key="index1" 
            @click="tabbarChange(item.path)">
            <cover-image class="item-img" :src="item.icon_a" v-if="current == index1"></cover-image>
            <cover-image class="item-img" :src="item.icon" v-else></cover-image>
            <cover-view class="item-name" :class="{'tabbarActive': current == index1}" v-if="item.text">{{item.text}}</cover-view>
        </cover-view>
    </cover-view>
</template>

<script>
export default {
    props: {
        current: String
    },
    data() {
        return {
            paddingBottomHeight: 0,  //苹果X以上手机底部适配高度
            list: [{
                    text: '首页',  
                    icon: '/static/img/home.png',  //未选中图标
                    icon_a: '/static/img/home-active.png',  //选中图片
                    path: "/pages/activity/index",  //页面路
                }
                ,{
                    text: '全部活动',
                    icon: '/static/img/huodong.png',
                    icon_a: '/static/img/huodong-active.png',
                    path: '/pages/activity/all',
                },{
                    text: '我的',
                    icon: '/static/img/wo.png',
                    icon_a: '/static/img/wo-active.png',
                    path: "/pages/activity/user",
                },
            ]
        };
    },
    created() {
        let that = this;
        uni.getSystemInfo({
            success: function (res) {
                let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
                model.forEach(item1 => {
                    //适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
                    if(res.model.indexOf(item1) != -1 && res.model.indexOf('iPhone') != -1) {
                        that.paddingBottomHeight = 40;
                    }
                })
            }
        });
    },
    watch: {
        
    },
    methods: {
        tabbarChange(path) {
			// alert(path)
   //          this.$pageTo.toTab(path);
			uni.navigateTo({
			    url:path
			})
            // uni.switchTab({
            //     url: path
            // })
        }
    }
};
</script>

<style lang="scss" scoped>
    .tabbarActive{
        color: #1296db !important;
    }
    .tabbar{
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 100rpx;
        background-color: #ffffff;
        display: flex;
        justify-content: space-around;
        align-items: center;
        .tabbar-item{
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100rpx;
            .item-img{
                width: 46rpx;
                height: 46rpx;
                margin-bottom: 4rpx;
            }
            .item-name{
                font-size: 26rpx;
                color: #A3A3A3;
            }
        }
    }
</style>